<template>
	<view class="content">
		<view class="list">
			<dy-item v-for="(item,index) in dymaniclist" @zan="zan(index)" @dyopsshow="dyopsshow(index)" :item="item"></dy-item>
		</view>
		<u-loadmore bg-color="#2A2931" :style="{padding: '20rpx 0'}" :status="status" />
		
		<u-action-sheet :list="dyops" @click="dyopclick" v-model="dyopshow"></u-action-sheet>
	</view>
</template>

<script>
	import dyItem from '@/components/dy-item.vue'
	export default {
		components:{
			dyItem
		},
		data() {
			return {
				dyopshow: false,
				dyops: [{
					text: '举报'
				}],
				HOSTURL:this.$HOSTURL,
				status: 'loadmore',
				selectlist:[],
				title:'',
				dymaniclist:[],
				data:{
					userid: this.$store.state.userid,
					count: 10,
					longitude: this.$store.state.longitude,
					latitude: this.$store.state.latitude,
					sex:0,
					new:1,
					category_id:0,
					recently:0,
					pagecount: 10,
					pagesize: 10,
					page: 0
				}
			}
		},
		onLoad(option) {
			this.title = option.text
			this.data.category_id = option.id
			uni.setNavigationBarTitle({
			    title: option.text
			});
			this.getDymanic()
		},
		methods: {
			dyopsshow(idx) {
				this.dyopidx = idx
				if(this.dymaniclist[idx].id == this.$store.state.userid){
					this.dyops = [{text: '删除'}]
				}else{
					this.dyops = [{text: '举报'}]
				}
				this.dyopshow = true
			},
			async dyopclick(index){
				if(this.dymaniclist[this.dyopidx].id == this.$store.state.userid){
					const {data:res} = await this.$Request({
						url: 'api/Member/delDymanic',
						data: {
							id: this.dymaniclist[this.dyopidx].dy_id
						}
					})
					this.$u.toast(res.msg);
					if (res && res.code == 200) {
						this.dymaniclist.splice(this.dyopidx, 1);
						this.dyopidx = -1
					}
				}else{
					this.nav('jubao','id',this.dymaniclist[this.dyopidx].id)
				}
			},
			nav(url, params, value) {
				uni.navigateTo({
					url: `/pages/${url}/index${params?'?'+params+'='+value:''}`
				})
			},
			// #ifdef MP
			onShareAppMessage() {
				const url = '/pages/index/index?share_id='+this.$store.state.userid
			    return {
			        title: this.$store.state.userinfo.name + "邀您来这里一起真实相约吧！",
			        path: url,
			        params: {},
					success(res){
					    uni.showToast({
					         title:'分享成功',
					        })
							console.log(url)
					    },
						
					fail(res){
					     uni.showToast({
					        title:'分享失败',
					        icon:'none'
							})
					}
					
			    };
			},
			// #endif
			async zan(index){
				const { data: res } = await this.$Request({
					url:'apis/home/Dymanic/thumbsup',
					data:{
						type: this.dymaniclist[index].isthumbsup==1 ? 2 : 1,
						dy_id: this.dymaniclist[index].dy_id,
						userid: this.$store.state.userid
					}
				})
				if(res.code==200){
					this.dymaniclist[index].isthumbsup = this.dymaniclist[index].isthumbsup==1 ? 0 : 1
					this.dymaniclist[index].isthumbsup==1 ? this.dymaniclist[index].num++ : this.dymaniclist[index].num--
				}
			},
			async getDymanic(){
				const { data: res } = await this.$Request({
					url:'apis/home/Dymanic/dymaniclst',
					data:this.data
				})
				if(!res) return false
				if(res.result.length<10){
					this.status = 'nomore';
				}
				this.dymaniclist = this.dymaniclist.concat(res.result)
			},
		},
		onReachBottom() {
			if(this.status != 'nomore'){
				this.status = 'loading';
				this.data.page++
				this.getDymanic()
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content{
		/* #ifndef H5 */
		min-height: 100vh;
		/* #endif */
		/* #ifdef H5 */
		min-height: calc(100vh - 44px);
		/* #endif */
		background: #2A2931;
	}
	.u-grid{
		image{
			width: 40rpx;
			height: 40rpx;
		}
	}
	.grid-text {
		font-size: 28rpx;
		margin-top: 10rpx;
		color: $u-type-info;
	}
	
	.selects{
		padding: 20rpx 0;
		background-color: #fff;
		display: flex;
		justify-content: space-around;
		.select{
			width: 33vw;
			text-align: center;
		}
	}
	.list{
		padding: 0rpx 0 30rpx 0;
	}
</style>
